package com.itheima.controller;


import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.itheima.pojo.Code;
import com.itheima.pojo.Employee;
import com.itheima.pojo.Result;
import com.itheima.pojo.User;
import com.itheima.service.impl.UserServiceImpl;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.sql.Time;
import java.util.concurrent.TimeUnit;

@Log4j2
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserServiceImpl userServiceImpl;
    @Autowired
    private RedisTemplate redisTemplate;

    @PostMapping("/sendMsg")
    public Result sendMsg(@RequestBody User user){
    return userServiceImpl.sendMsg(user);
    }

    @PostMapping("/login")
    public Result login(@RequestBody User user){
     return userServiceImpl.login(user);
    }

    @PostMapping("/loginout")
    public Result loginout(HttpServletRequest request){
        String token = request.getHeader("AuthorizationUser");
        redisTemplate.delete(token);
        return new Result(Code.OK, null, "{}");
    }
}
